<template>
  <el-dialog :title="title" :visible.sync="dialogAddNew" width="50%" center>
    <el-form ref="warehouseForm" :model="form" :rules="rules">
      <el-form-item label="仓库名称" :label-width="formLabelWidth" prop="warehouse_name">
        <el-input v-model="form.warehouse_name" autocomplete="off" :disabled="isDisable" />
      </el-form-item>
      <el-form-item label="公司" :label-width="formLabelWidth">
        <el-input v-model="form.company" autocomplete="off" :disabled="isDisable" />
      </el-form-item>
      <el-form-item label="名称描述" :label-width="formLabelWidth">
        <el-input v-model="form.desc" autocomplete="off" :disabled="isDisable" />
      </el-form-item>
      <el-form-item label="地址" :label-width="formLabelWidth">
        <el-input v-model="form.address" autocomplete="off" :disabled="isDisable" />
      </el-form-item>
      <el-form-item label="场所" :label-width="formLabelWidth">
        <el-input v-model="form.place" autocomplete="off" :disabled="isDisable" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogAddNew = false">取 消</el-button>
      <el-button :disabled="isDisable" type="primary" @click="addFun('warehouseForm')">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { operationWarehouseInfo } from '@/api/wms'
export default {
  props: {
    title: {
      type: String,
      default: '新增'
    }
    // dialogAddNew: {
    //   type: Boolean,
    //   default: true
    // }
  },
  data() {
    return {
      form: {
        warehouse_name: '',
        company: '',
        place: '',
        address: '',
        desc: ''
      },
      rules: {
        warehouse_name: [
          { required: true, message: '请输入仓库编号', trigger: 'blur' }
        ]
      },
      dialogFormVisible: false,
      formLabelWidth: '80px',
      dialogAddNew: false,
      type: 1,
      isDisable: false
    }
  },
  created() {
  },
  methods: {
    addFun(formName) {
      console.log('confirm')
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const data = {
            type: this.type,
            pro: this.form,
            id: this.id
          }
          operationWarehouseInfo(data).then(res => {
            console.log(res)
            if (res.code === 200) {
              this.$message.success(this.type === 1 ? '仓库信息添加成功！' : '仓库信息更改成功！')
              this.dialogAddNew = false
              this.form = { warehouse_name: '',
                company: '',
                place: '',
                address: '',
                desc: '' }
              this.$emit('reloadData')
            } else {
              this.$message.info('仓库信息上传失败！请重新上传')
              this.dialogAddNew = false
            }
          })
        } else {
          alert('submit err')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
